package com.ymatou.iapi.userservice.testcase;

import java.util.Random;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.parameter.req.SetUserProfileReq;
import com.ymatou.iapi.userservice.service.SetUserProfileCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.model.Userinfoex;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.utils.TestDataManager;
/**
*绑定邮箱Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SetUserProfile{
	private static SetUserProfileReq SetUserProfileBean;
	private static SetUserProfileCall SetUserProfileCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置用户基本信息");
	}

	@Before
	public void caseUp() {
		SetUserProfileBean=new SetUserProfileReq();
		SetUserProfileCall=new SetUserProfileCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(SetUserProfileCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetUserProfile_001() {
		Logger.start(true,"设置用户基本信息,成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			SetUserProfileBean.setMsn(TestDataManager.getEmail());
			SetUserProfileBean.setPhone(TestDataManager.getPhoneNum());
			SetUserProfileBean.setQq(TestDataManager.getRandomNum(7));
			SetUserProfileBean.setWang(TestDataManager.getEmail());
			SetUserProfileBean.setUserGender(new Random().nextInt(2));
			SetUserProfileBean.setUserId(uid);
			SetUserProfileCall.setData(SetUserProfileBean);
			SetUserProfileCall.callService();
			Logger.verifyEquals("true", SetUserProfileCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", SetUserProfileCall.getString("ResponseCode"), "验证ResponseCode");
			Userinfoex info = new JUserWapper().selectUserinfoexByUid(uid).get(0);
			Userinfo info2 = new JUserWapper().selectUserinfoByUid(uid).get(0);
			Logger.verifyEquals(SetUserProfileBean.getQq(), info.getQQ(), "验证qq");
			Logger.verifyEquals(SetUserProfileBean.getMsn(), info.getMsn(), "验证msn");
			Logger.verifyEquals(SetUserProfileBean.getWang(), info.getWang(), "验证wang");
			Logger.verifyEquals(SetUserProfileBean.getPhone(), info.getTelephone(), "验证phone");
			Logger.verifyEquals(SetUserProfileBean.getUserGender(), info2.getUserGender(), "验证qq");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SetUserProfile_002() {
		Logger.start(false,"不输入userid，失败");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
//			Integer uid = JUserCallService.createUserCall(cur);
			SetUserProfileBean.setMsn(TestDataManager.getEmail());
			SetUserProfileBean.setPhone(TestDataManager.getPhoneNum());
			SetUserProfileBean.setQq(TestDataManager.getRandomNum(7));
			SetUserProfileBean.setWang(TestDataManager.getEmail());
			SetUserProfileBean.setUserGender(new Random().nextInt(2));
//			SetUserProfileBean.setUserId(uid);
			SetUserProfileCall.setData(SetUserProfileBean);
			SetUserProfileCall.callService();
			Logger.verifyEquals("false", SetUserProfileCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100", SetUserProfileCall.getString("ResponseCode"), "验证ResponseCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SetUserProfile_003() {
		Logger.start(false,"输入userid 错误，失败");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
//			Integer uid = JUserCallService.createUserCall(cur);
			SetUserProfileBean.setMsn(TestDataManager.getEmail());
			SetUserProfileBean.setPhone(TestDataManager.getPhoneNum());
			SetUserProfileBean.setQq(TestDataManager.getRandomNum(7));
			SetUserProfileBean.setWang(TestDataManager.getEmail());
			SetUserProfileBean.setUserGender(new Random().nextInt(2));
			SetUserProfileBean.setUserId(-1);
			SetUserProfileCall.setData(SetUserProfileBean);
			SetUserProfileCall.callService();
			Logger.verifyEquals("false", SetUserProfileCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100", SetUserProfileCall.getString("ResponseCode"), "验证ResponseCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetUserProfile_004() {
		Logger.start(true,"重复设置用户基本信息,成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			SetUserProfileBean.setMsn(TestDataManager.getEmail());
			SetUserProfileBean.setPhone(TestDataManager.getPhoneNum());
			SetUserProfileBean.setQq(TestDataManager.getRandomNum(7));
			SetUserProfileBean.setWang(TestDataManager.getEmail());
			SetUserProfileBean.setUserGender(new Random().nextInt(2));
			SetUserProfileBean.setUserId(uid);
			SetUserProfileCall.setData(SetUserProfileBean);
			SetUserProfileCall.callService();
			
			SetUserProfileBean.setMsn(TestDataManager.getEmail());
			SetUserProfileBean.setPhone(TestDataManager.getPhoneNum());
			SetUserProfileBean.setQq(TestDataManager.getRandomNum(7));
			SetUserProfileBean.setWang(TestDataManager.getEmail());
			SetUserProfileBean.setUserGender(new Random().nextInt(2));
			SetUserProfileBean.setUserId(uid);
			SetUserProfileCall.setData(SetUserProfileBean);
			SetUserProfileCall.callService();
			
			
			Logger.verifyEquals("true", SetUserProfileCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", SetUserProfileCall.getString("ResponseCode"), "验证ResponseCode");
			Userinfoex info = new JUserWapper().selectUserinfoexByUid(uid).get(0);
			Userinfo info2 = new JUserWapper().selectUserinfoByUid(uid).get(0);
			Logger.verifyEquals(SetUserProfileBean.getQq(), info.getQQ(), "验证qq");
			Logger.verifyEquals(SetUserProfileBean.getMsn(), info.getMsn(), "验证msn");
			Logger.verifyEquals(SetUserProfileBean.getWang(), info.getWang(), "验证wang");
			Logger.verifyEquals(SetUserProfileBean.getPhone(), info.getTelephone(), "验证phone");
			Logger.verifyEquals(SetUserProfileBean.getUserGender(), info2.getUserGender(), "验证qq");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}